<template>
    <div>
        <Button type='primary' ghost @click="issue()"  :disabled="disabledAllBtn" style="margin:20px 0px;">下发数据</Button>
        <Button type='primary' ghost @click="synchronizeAttachments()"  style="margin:20px 20px;" v-if="type!=0">同步题目附件</Button>
        <!-- <Button type='primary' ghost @click="issueAccessGroup()"  :disabled="disabledAllBtn" style="margin:20px 20px;">下发接入组</Button> -->
        <Table :columns="columns" :data="rangeList"></Table>
    </div>
</template>

<script>
import {issueCompetitionData,queryRangeInformation,issueAccessGroup,synchronizeAttachments} from '@/api/drill_compete'
export default {
    props: ['type', 'disabledAllBtn','isDistributed'],
    data(){
        return {
            rangeList:[],
            columns: [
                    {
                        title: '靶场名称',
                        key: 'rangeName',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: '是否为主靶场',
                        key: 'rangeName',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                        render: (h, params) => {
                            return h('span', this.typeFilter(params.row.parent))
                        }
                    },

                    {
                        title: '准备情况',
                        key: 'rangeName',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                        width:100,
                         render: (h, params) => {
                            return h('span',  this.statusFilter(params.row.status))
                        },
                        // render: (h, params) => {
                        //     return h('Tooltip', {
                        //         props: { placement: 'top-end', content:params.row.msg}
                        //     },
                        //      [
                        //         h('span', [
                        //             h('span', this.statusFilter(params.row.status)),
                        //             h('i', {
                        //                 class: 'ivu-icon ivu-icon-md-alert',
                        //                 style: {
                        //                     fontSize: '14px',
                        //                     marginLeft: '5px',
                        //                     marginRight: '14px',
                        //                     color:'#ff0000',
                        //                     display:params.row.status==2?'inline-block':'none'
                        //                 },
                        //             })
                        //         ]),
                        //         h('span', {
                        //             slot: 'content',
                        //         }, params.row.msg)
                        //     ])
                        // }
                    },
                    {
                        title: '异常情况',
                        key: 'rangeName',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                        render: (h, params) => {
                            return h('span',params.row.status==2? params.row.msg:'暂无异常')
                        }
                    },
                    
                    {
                        title: '任务ID  ',
                        key: 'taskId',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: '靶场ID',
                        key: 'rangeId',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: '工程ID',
                        key: 'proejctId',
                        align: 'center',
                        ellipsis: true,
                        tooltip: true,
                    }
                ],
        }
    },
    mounted(){
        this.queryRangeInformation()
    },
    methods:{
        synchronizeAttachments(){
            synchronizeAttachments(this.$route.query.id).then(res=>{
                if(res.code==1){
                    this.$Message.success(res.message)
                } else{
                    this.$Message.warning(res.message)
                }
            })
        },
        issueAccessGroup(){
            issueAccessGroup(this.$route.query.id).then(res=>{
                if(res.code==1){
                    this.$Message.success('下发成功')
                } else{
                    this.$Message.warning('下发失败')
                }
            })
        },
        issue(){
            issueCompetitionData(this.$route.query.id).then(res=>{
                if(res.code==1){
                    this.$Message.success('下发成功')
                    this.queryRangeInformation()
                } else{
                    this.$Message.warning(res.message)
                }
            })
        },
        queryRangeInformation(){
            queryRangeInformation(this.$route.query.id).then(res=>{
                if(res.code==1){
                    this.rangeList=res.data.items
                } else{
                    this.$Message.warning('查询分靶场信息失败')
                }
            })
        },
        typeFilter(val) {
            let str = '';
            switch (val) {
                case 0:
                    str = '否';
                    break;
                case 1:
                    str = '是';
                    break;
                default:
                    str = '未定义类型';
                    break;
            }
            return str;
        },
        statusFilter(val) {
            let str = '';
            switch (val) {
                case 0:
                    str = '未准备完成';
                    break;
                case 1:
                    str = '准备完成';
                    break;
                case 2:
                    str = '准备失败';
                    break;
                default:
                    str = '未定义类型';
                    break;
            }
            return str;
        },
    },
}
</script>

<style>

</style>